package cn.wolfcode.luowowo.website.web.advice;

import cn.wolfcode.luowowo.common.exception.LogicException;
import cn.wolfcode.luowowo.common.util.AjaxResult;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.io.IOException;

/**
 * 控制器功能增强注解
 * 在请求映射方法处理前或者处理后对请求映射方法做功能性增强
 */
@ControllerAdvice
public class CommonExceptionHandler {

    @ExceptionHandler(LogicException.class)
    @ResponseBody
    public Object displayExp(Exception e) throws IOException {
        e.printStackTrace();
        return new AjaxResult(false,e.getMessage());
    }

    @ExceptionHandler(RuntimeException.class)
    @ResponseBody
    public Object runTimeExp(Exception e) throws IOException {
        e.printStackTrace();
        return new AjaxResult(false,"系统繁忙,稍后请联系管理员");
    }
}
